package com.example.zhouhao2022050651

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import com.example.zhouhao2022050651.databinding.ActivityMain2Binding
import com.example.zhouhao2022050651.Student

class MainActivity2 : AppCompatActivity() {

    private lateinit var binding: ActivityMain2Binding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMain2Binding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.retur.setOnClickListener {
            val stuno = binding.editText1.text.toString()
            val sname = binding.editText2.text.toString()
            val sex = binding.editText3.text.toString()
            val stuclass = binding.editText4.text.toString()
            val newStudent = Student(stuno, sname, sex, stuclass)
            val intent = Intent()
            intent.putExtra("newStudent", newStudent)
            setResult(RESULT_OK, intent)
            finish()
        }

        binding.cancel.setOnClickListener {
            finish()
        }
    }
}